var rootPath = getRootPath();
var oriPhone;

$(function() {
	var rleId = getUrlParam("rleId");
	$("#rleId").val(rleId);
	createProvSelect(document.getElementById("province"));
	createGradeSelect(document.getElementById("gid"),"2");
	focusById();
	
	//反显数据
	$.ajax({
		url : rootPath + '/verify/uid/rleId/' + rleId + '/dr/1',
		method : "GET",
		success : function(data) {
			if(data.returnCode == '0000') {
				if(data.returnObject != null) {
					var obj = data.returnObject;
					if(obj.company!=null && obj.company!=""){
						$("#company").val(obj.company);
					}
					if(obj.grade.gid!=null && obj.grade.gid!=""){
						$("#gid option[value='"+obj.grade.gid+"']").attr("selected","selected");
					}
					if(obj.province!=null && obj.province!=""){
						$("#province option[value='"+obj.province+"']").attr("selected","selected");
						$("#province").change();
					}
					if(obj.city!=null && obj.city!=""){
						$("#city option[value='"+obj.city+"']").attr("selected","selected");
						$("#city").change();
					}
					if(obj.area!=null && obj.area!=""){
						$("#area option[value='"+obj.area+"']").attr("selected","selected");
					}
					if(obj.address!=null && obj.address!=""){
						$("#address").val(obj.address);
					}
					if(obj.intro!=null && obj.intro!=""){
						$("#intro").val(obj.intro);
					}
					if(obj.contact!=null && obj.contact!=""){
						$("#contact").val(obj.contact);
					}
					/*if(obj.job!=null && obj.job!=""){
						$("#job").val(obj.job);
					}*/
					if(obj.phone!=null && obj.phone!=""){
						$("#phone").val(obj.phone);
						oriPhone = obj.phone
					}
					if(obj.wechat!=null && obj.wechat!=""){
						$("#wechat").val(obj.wechat);
					}
				}
			}
		},
		error: function (jqXHR, textStatus, errorThrown) {
			layer.alert("error");
		}
	});
	
});

function showErrMsg(id,msg){
	$("#" + id + "Tip").text(msg);
	$("#"+id+"Msg").show();
}

function hideMsg(id) {
	$("#"+id+"Msg").hide();
}

function focusById(){
	$("#company").focus(function(){
		hideMsg("company");
	});
	$("#gid").focus(function(){
		hideMsg("gid");
	});
	$("#province,#city,#area").focus(function(){
		hideMsg("area");
	});
	$("#address").focus(function(){
		hideMsg("address");
	});
	$("#intro").focus(function(){
		hideMsg("intro");
	});
	$("#contact").focus(function(){
		hideMsg("contact");
	});
	/*$("#job").focus(function(){
		hideMsg("job");
	});*/
	$("#phone").focus(function() {
		hideMsg("phone");
	});
	$("#wechat").focus(function(){
		hideMsg("wechat");
	});
}